package com.itheima.controller;

import com.github.pagehelper.Page;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.dto.CheckGroupDTO;
import com.itheima.pojo.entity.CheckGroup;
import com.itheima.service.CheckGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {

    @Autowired
    private CheckGroupService checkGroupService;

    @PostMapping("/add")
    public Result addCheckGroup(@RequestBody CheckGroupDTO checkGroupDTO){
        checkGroupService.addCheckGroup(checkGroupDTO);
        return new Result(true,"新增检查组成功");
    }

    @GetMapping("deleteById")
    public Result deleteById(String id){
        checkGroupService.deleteById(id);
        return new Result(true,"删除检查组成功");
    }

    /**
     * 根据套餐id查询关联的检查项id
     * @param setmealId
     * @return
     */
    @GetMapping("/findCheckGroupIdsBySetmealId")
    public Result findCheckGroupIdsBySetmealId(String setmealId){
        List<Integer> list=checkGroupService.findCheckGroupIdsBySetmealId(setmealId);
        return new Result(true,"查询检查组成功",list);
    }

    @PostMapping("/findPage")
    public PageResult findPageCheckGroup(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult =checkGroupService.findPageCheckGroup(queryPageBean);
        return pageResult;
    }

    @PostMapping("/edit")
    public Result editCheckGroup(@RequestBody CheckGroup checkGroup){
        checkGroupService.editCheckGroup(checkGroup);
        return new Result(true,"编辑检查组成功");
    }

    @GetMapping("findAll")
    public Result findAllCheckGroup(){
        List<CheckGroup> list=checkGroupService.findAllCheckGroup();
        return new Result(true,"查询检查组成功",list);
    }

    @GetMapping("/findById")
    public Result findByIdCheckGroup(String id){
        CheckGroup checkGroup =checkGroupService.findByIdCheckGroup(id);
        return new Result(true,"查询检查组成功",checkGroup);
    }
}
